import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/register',
    name: 'Register',
    component: () => import('@/views/login/register'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  
  {
    path: '/final',
    component: () => import('@/views/quick/previewBg.vue'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '控制台', icon: 'dashboard', affix: true },
        hidden:true
      },

      {
        path: 'qu/view/:id',
        component: () => import('@/views/qu/qu/view'),
        name: 'ViewQu',
        meta: { title: '题目详情', noCache: true, activeMenu: '/manage/qu' },
        hidden: true
      }
    ]
  },

  {
    path: '/profile',
    component: Layout,
    redirect: '/profile/index',
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/profile/index'),
        name: 'Profile',
        meta: { title: '个人资料', icon: 'user', noCache: true }
      }
    ]
  }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [

  {
    path: '/exam/start/:id',
    component: () => import('@/views/paper/exam/exam'),
    name: 'StartExam',
    meta: { title: '开始考试' },
    hidden: true
  },

  {
    path: '/exam/start-safety/:id',
    component: () => import('@/views/paper/safetyExam/exam.vue'),
    name: 'StartSafetyExam',
    meta: { title: '开始考试' },
    hidden: true
  },

  {
    path: '/exam/startpop/:id',
    component: () => import('@/views/paper/populationExam/index.vue'),
    name: 'StartPopExam',
    meta: { title: '开始考试' },
    hidden: true
  },

  {
    path: '/exam/start-fence/:id',
    component: () => import('@/views/paper/fence_off/exam.vue'),
    name: 'StartFenceExam',
    meta: { title: '开始考试' },
    hidden: true
  },


  
  // 决赛
  {
    path: '/quick/start-requird',
    component: () => import('@/views/quick/exam/required/indexStateR.vue'),
    name: 'StartRequired',

    meta: { title: '必答' },
    hidden: true
  },

  {
    path: '/quick/start-responder',
    component: () => import('@/views/quick/exam/responder/indexStateRoll.vue'),
    name: 'StartResponder',
    meta: { title: '抢答' },
    hidden: true
  },

  {
    path: '/quick/start-scene',
    component: () => import('@/views/quick/exam/scene/indexStateRoll.vue'),
    name: 'StartScene',
    meta: { title: '法制教育' },
    hidden: true
  },
  
  {
    path: '/quick/start-pop',
    component: () => import('@/views/quick/population/indexStateRoll.vue'),
    name: 'StartPopulatiopn',
    meta: { title: '实有人口' },
    hidden: true
  },

  {
    path: '/quick/start-safety',
    component: () => import('@/views/quick/saftey'),
    name: 'StartSafety',
    meta: { title: '安全隐患' },
    hidden: true
  },

  {
    path: '/quick/start-specific',
    component: () => import('@/views/quick/specific/index.vue'),
    name: 'StartSpecific',
    meta: { title: '特定人口' },
    hidden: true
  },

  {
    path: '/quick/start-fence',
    component: () => import('@/views/quick/fence_off/indexStateRoll.vue'),
    name: 'StartFence',
    meta: { title: '理论知识抢答题' },
    hidden: true
  },

  {
    path: '/online',
    // component: Layout,
    component : ()=> import('@/views/paper'),
    redirect: '/online/exam',
    name: 'Online',
    meta: {
      title: '初赛',
      icon: 'list'
    },
    children: [

      {
        path: 'exam',
        component: () => import('@/views/paper/exam/previewBg.vue'),
        name: 'ExamPaper',
        meta: { title: '初赛', noCache: true, icon: 'guide' },
        // hidden:true
      },

      {
        path: 'exam-paper',
        component: () => import('@/views/paper/exam/previewBg.vue'),
        name: 'ListExam',
        meta: { title: '理论知识考试', noCache: true, icon: 'guide' },
        hidden:true
      },

      {
        path: 'populationExam',
        component: () => import('@/views/paper/populationExam/previewBg.vue'),
        name: 'PopulationExam',
        meta: { title: '实有人口管理', noCache: true, icon: 'guide' },
        hidden:true
      },

      {
        path: 'safetyExam',
        component: () => import('@/views/paper/safetyExam/previewBg.vue'),
        name: 'SafetyExam',
        meta: { title: '场所单位隐患检视', noCache: true, icon: 'guide' },
        hidden:true
      },

      {
        path: 'fence-exam',
        component: () => import('@/views/paper/fence_off/previewBg.vue'),
        name: 'FenceExam',
        meta: { title: '加赛', noCache: true, icon: 'guide' },
        hidden:true
      },

      {
        path: 'exam/prepare/:examId',
        component: () => import('@/views/paper/exam/preview'),
        name: 'PreExam',
        meta: { title: '准备考试', noCache: true, activeMenu: '/online/exam' },
        hidden: true
      },

      {
        path: 'exam/result/:id',
        component: () => import('@/views/paper/exam/result'),
        name: 'ShowExam',
        meta: { title: '考试结果', noCache: true, activeMenu: '/online/exam' },
        hidden: true
      },

      {
        path: 'exam/result-pop/:id',
        component: () => import('@/views/paper/populationExam/result.vue'),
        name: 'ShowPopExam',
        meta: { title: '考试结果', noCache: true, activeMenu: '/online/populationExam' },
        hidden: true
      },

      {
        path: 'exam/result-safety/:id',
        component: () => import('@/views/paper/safetyExam/result.vue'),
        name: 'ShowSafety',
        meta: { title: '考试结果', noCache: true, activeMenu: '/online/populationExam' },
        hidden: true
      },

      {
        path: 'exam/result-fence/:id',
        component: () => import('@/views/paper/fence_off/result.vue'),
        name: 'ShowFence',
        meta: { title: '考试结果', noCache: true, activeMenu: '/online/populationExam' },
        hidden: true
      },

      {
        path: 'exam/correct/:id',
        component: () => import('@/views/paper/paper/correct.vue'),
        name: 'CorrectPaper',
        meta: { title: '批改试卷', noCache: true, activeMenu: '/online/exam' },
        hidden: true
      },

      // {
      //   path: 'tran',
      //   component: () => import('@/views/user/book'),
      //   name: 'ListTran',
      //   meta: { title: '错题训练', noCache: true, icon: 'study' }
      // },

      {
        path: 'tran/start',
        component: () => import('@/views/user/book/train'),
        name: 'StartTran',
        meta: { title: '错题训练2', noCache: true, activeMenu: '/online/tran' },
        hidden: true
      },

      {
        path: 'exam/records',
        component: () => import('@/views/paper/paper'),
        name: 'ListMyPaper',
        meta: { title: '考试记录', noCache: true, icon: 'paper' },
        hidden:true
      },

      {
        path: 'exam/records-pop',
        component: () => import('@/views/paper/paper/indexPop.vue'),
        name: 'ListMyPaperPop',
        meta: { title: '实有人口考试记录', noCache: true, icon: 'paper' },
        hidden:true
      }

    ]
  },
  {
    path: '/race',
    // component: Layout,
    component: () => import('@/views/quick'), // 直接加载目标组件
    redirect: '/race/quick',
    name: 'Quick',
    meta: {
      title: '决赛',
      icon: 'example',
      noCache: true,
      roles: ['sa', 'teacher']
    },
    children: [

      {
        path: '/quick',
        component: () => import('@/views/quick/previewBg.vue'),
        name: 'QuickPreview',
        meta: { title: '决赛', noCache: true, icon: 'repo'},
        // hidden:true
      },
      

      {
        path: '/quick/scene',
        component: () => import('@/views/quick/exam/scene/previewBg.vue'),
        name: 'QuickScene',
        meta: { title: '社区警务基础场景处置', noCache: true, icon: 'repo'},
        hidden:true
      },

      {
        path: '/quick/show',
        component: () => import('@/views/quick/show/previewBg.vue'),
        name: 'ShowImg',
        meta: { title: 'ppt', noCache: true,icon:'repo' },
        hidden: true
      },

      {
        path: 'theory',
        component: () => import('@/views/quick/exam'),
        name: 'QuickTheory',
        redirect: '/race/theory', 
        meta: { title: '理论知识答题', noCache: true, icon: 'repo' },
        hidden: true,
        children: [
          {
            path: 'required',
            component: () => import('@/views/quick/exam/required/previewBg.vue'),
            name: 'QuickRequired',
            meta: { title: '必答', noCache: true, icon: 'repo' },
            hidden: true
          },
          {
            path: 'responder',
            component: () => import('@/views/quick/exam/responder/previewBg.vue'),
            name: 'QuickResponder',
            meta: { title: '抢答', noCache: true, icon: 'repo' }
          },
          // {
          //   path: 'scene',
          //   component: () => import('@/views/quick/exam/scene/preview.vue'),
          //   name: 'QuickScene',
          //   meta: { title: '法制宣讲', noCache: true, icon: 'repo' }
          // }
        ]
      },

      // {
      //   path: '/quick/required',
      //   component: () => import('@/views/quick/exam/required/preview.vue'),
      //   name: 'QuickRequired',
      //   meta: { title: '必答', noCache: true, icon: 'repo'}
      // },

      // {
      //   path: '/quick/responder',
      //   component: () => import('@/views/quick/exam/responder/preview.vue'),
      //   name: 'QuickResponder',
      //   meta: { title: '抢答', noCache: true, icon: 'repo'}
      // },

      {
        path: '/quick/pop',
        component: () => import('@/views/quick/population/previewBg.vue'),
        name: 'ListQuick',
        meta: { title: '实有人口管理', noCache: true, icon: 'repo'},
        hidden: true

      },
      {
        path: '/quick/specific',
        component: () => import('@/views/quick/specific/preview.vue'),
        name: 'Specific',
        meta: { title: '特定人口', noCache: true,icon:'repo' },
        hidden:true
      },

      {
        path: '/quick/saftey',
        component: () => import('@/views/quick/saftey/previewBg.vue'),
        name: 'Saftey',
        meta: { title: '场所单位隐患视检', noCache: true,icon:'repo' },
        hidden: true

      },

      {
        path: '/quick/fence-off',
        component: () => import('@/views/quick/fence_off/previewBg.vue'),
        name: 'FenceOff',
        meta: { title: '理论知识抢答题', noCache: true,icon:'repo' },
        hidden: true
      },

     


      // {
      //   path: '/quick/scene',
      //   component: () => import('@/views/quick/exam/scene/preview.vue'),
      //   name: 'QuickScene',
      //   meta: { title: '法制宣讲', noCache: true, icon: 'repo'}
      // },
      
    ]
  },
  {
    path: '/manage',
    component: Layout,
    redirect: '/manage/qu',
    name: 'Manage',
    meta: {
      title: '考试管理',
      icon: 'example',
      roles: ['sa', 'teacher']
    },
    children: [

      {
        path: 'repo',
        component: () => import('@/views/qu/repo'),
        name: 'ListRepo',
        meta: { title: '题库管理', noCache: true, icon: 'repo' }
      },

      {
        path: 'repo/add',
        component: () => import('@/views/qu/repo/form'),
        name: 'AddRepo',
        meta: { title: '添加题库', noCache: true, activeMenu: '/manage/repo' },
        hidden: true
      },

      {
        path: 'repo/update/:id',
        component: () => import('@/views/qu/repo/form'),
        name: 'UpdateRepo',
        meta: { title: '题库详情', noCache: true, activeMenu: '/manage/repo' },
        hidden: true
      },

      {
        path: 'qu',
        component: () => import('@/views/qu/qu'),
        name: 'ListQu',
        meta: { title: '试题管理', noCache: true, icon: 'support' }
      },

      {
        path: 'qu/add',
        component: () => import('@/views/qu/qu/form'),
        name: 'AddQu',
        meta: { title: '添加试题', noCache: true, activeMenu: '/manage/qu' },
        hidden: true
      },

      {
        path: 'qu/update/:id',
        component: () => import('@/views/qu/qu/form'),
        name: 'UpdateQu',
        meta: { title: '修改试题', noCache: true, activeMenu: '/manage/qu' },
        hidden: true
      },

      {
        path: 'rule',
        component: () => import('@/views/paper/rule'),
        name: 'ListRule',
        meta: { title: '规则管理', noCache: true, icon: 'topic' }
      },

      {
        path: 'rule/add',
        component: () => import('@/views/paper/rule/form'),
        name: 'AddRule',
        meta: { title: '添加规则', noCache: true, activeMenu: '/manage/rule' },
        hidden: true
      },

      {
        path: 'rule/update/:id',
        component: () => import('@/views/paper/rule/form'),
        name: 'UpdateRule',
        meta: { title: '修改规则', noCache: true, activeMenu: '/manage/rule' },
        hidden: true
      },

      {
        path: 'exam',
        component: () => import('@/views/exam/exam'),
        name: 'ListExam',
        meta: { title: '考试管理', noCache: true, icon: 'log' }
      },

      {
        path: 'exam/records',
        component: () => import('@/views/paper/paper'),
        name: 'ListMyPaper',
        meta: { title: '考试记录', noCache: true, icon: 'paper' },
        // hidden:true
      },

      {
        path: 'exam/records-pop',
        component: () => import('@/views/paper/paper/indexPop.vue'),
        name: 'ListMyPaperPop',
        meta: { title: '实有人口考试记录', noCache: true, icon: 'paper' },
        // hidden:true
      },

      {
        path: 'review-paper/:examId',
        component: () => import('@/views/paper/paper/review'),
        name: 'ReviewPaper',
        meta: { title: '批阅试卷', noCache: true, icon:"paper" },
        // hidden: true
      },

      {
        path: 'exam/add',
        component: () => import('@/views/exam/exam/form'),
        name: 'AddExam',
        meta: { title: '添加考试', noCache: true, activeMenu: '/manage/exam' },
        hidden: true
      },

      {
        path: 'exam/update/:id',
        component: () => import('@/views/exam/exam/form'),
        name: 'UpdateExam',
        meta: { title: '修改考试', noCache: true, activeMenu: '/manage/exam' },
        hidden: true
      }
    ]
  },

  {
    path: '/sys',
    component: Layout,
    redirect: '/sys/config',
    name: 'Sys',
    meta: {
      title: '系统设置',
      icon: 'configure',
      roles: ['sa']
    },
    children: [

      {
        path: 'role',
        component: () => import('@/views/sys/role'),
        name: 'SysRole',
        meta: { title: '角色管理', icon: 'role' }
      },

      {
        path: 'user',
        component: () => import('@/views/sys/user'),
        name: 'SysUser',
        meta: { title: '用户管理', icon: 'admin' }
      },

      {
        path: 'syslog',
        component: () => import('@/views/sys/log'),
        name: 'SysLog',
        meta: { title: '系统日志', icon: 'log' }
      }

    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/dashboard', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
